package com.link.base.base.menupageurls.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.link.base.base.common.model.Menu;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.link.base.base.menupageurls.model.MenuPageUrls;
import com.link.base.base.menupageurls.service.MenuPageUrlsService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 菜单下页面路径
 *
 * @author 秦学刚
 * @date 2020-07-03 16:14:08
 */
@Controller
@RequestMapping("/link/menuPageUrls")
public class MenuPageUrlsController extends BasicController<MenuPageUrls> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private MenuPageUrlsService menuPageUrlsService;

    @Override
    public BasicService<MenuPageUrls> getBasicService() throws Exception {
        return menuPageUrlsService;
    }

    /**
     * CRM/DMS 添加菜单下的路径到中间表
     *
     * @author qinxg
     * @date 2020/7/7
     * @param entity
     * @param session
     * @param request
     * @param response
     * @return
     **/
    @RequestMapping({"/addPageUrlAll"})
    @ResponseBody
    public Map<String, Object> addPageUrlAll(@JsonParam Menu entity, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        HashMap result = new HashMap(4);
        try {
            if (entity == null || entity.getMenuUrl() == null || entity.getId() == null || StringUtils.isBlank(entity.getPlatformType())) {
                throw new Exception("缺少菜单信息，请检查数据");
            }
            menuPageUrlsService.addPageUrlAll(entity);
            result.put("success", true);
            result.put("code", "200");
        } catch (Exception var8) {
            result.put("success", false);
            result.put("result", var8.getMessage());
            result.put("code", "400");
        }
        return result;
    }


    /**
     * CRM/DMS 增加所有一级菜单下的所有二级菜单页面以及关联页面的URL到URL配置表中
     *
     * @author qinxg
     * @date 2020/7/7
     * @param entity
     * @param session
     * @param request
     * @param response
     * @return
     **/
    @RequestMapping({"/addFirstMenuPageUrlAll"})
    @ResponseBody
    public Map<String, Object> addFirstMenuPageUrlAll(@JsonParam Menu entity, HttpSession session,
                                                      HttpServletRequest request, HttpServletResponse response) {
        HashMap result = new HashMap(4);
        try {
//            if (entity == null || entity.getId() == null) {
//                throw new Exception("缺少菜单信息，请检查数据");
//            }
            menuPageUrlsService.addFirstMenuPageUrlAll();
            result.put("success", true);
            result.put("code", "200");
        } catch (Exception var8) {
            result.put("success", false);
            result.put("result", var8.getMessage());
            result.put("code", "400");
        }
        return result;
    }
}